home *** CD-ROM | disk | FTP | other *** search
/ Computer Inter@ctive 17 / Computer Interactive cdrom 17 - gen 99.iso / ZDNETIT / CONTENT / OPTIVC16.ZIP / DOC.ZIP / CMATH.TXT next >
Encoding:
Text File  |  1998-10-21  |  36.5 KB  |  799 lines

  1.     CCCCCCC     MM         MM          A         TTTTTTTTTT    HH      HH
  2.   CC            MMM       MMM         AAA            TT        HH      HH
  3.  CCC            MMMM     MMMM        AA AA           TT        HH      HH
  4.  CCC            MM MM   MM MM       AA   AA          TT        HHHHHHHHHH
  5.  CCC            MM  MM MM  MM      AAAAAAAAA         TT        HH      HH
  6.   CC            MM   MMM   MM     AA       AA        TT        HH      HH
  7.     CCCCCCC     MM    M    MM    AA         AA       TT        HH      HH
  8.  
  9.  
  10.                     CMATH 1.2  for Borland C++
  11.                      (Version 3.0 or higher)
  12.  
  13.                     Dr. Martin Sander Software Development
  14.                     Sertürnerstr. 11
  15.                     D-37085 Göttingen
  16.                     Germany
  17.                     e-mail: MartinSander@Bigfoot.com
  18.                     http://www.optivec.com
  19.  
  20. For the commercial version, please order by e-mail or through our web-site!
  21.  
  22. *****************************************************************************
  23.  
  24. !!     This is an ASCII text file!  It is best viewed with a simple        !!
  25. !!     DOS editor.                                                         !!
  26. !!     If you load this file into a word processor under Windows, you      !!
  27. !!     must use the filter "DOS text".                                     !!
  28. !!     Alternatively, you may use FCONVERT (shipped with Borland C++) to   !!
  29. !!     convert from ASCII (OEM) into the ANSI character set.               !!
  30. !!     preferably use the lettertype CourierNew 10 pt.                     !!
  31.  
  32.                  **************************************
  33.    German-speaking users:
  34.        Um die Kosten für das Herunterladen der Shareware-Version
  35.        über das Internet für alle so gering wie möglich zu halten,
  36.        enthält diese nur die englische Dokumentation. Sie finden
  37.        die deutsche Beschreibung separat unter
  38.                http://www.gwdg.de/~msander/Download/BC/CMDOCD.ZIP
  39.                  **************************************
  40.  
  41. OptiCode (TM) and OptiVec (TM) are trademarks of Dr. Martin Sander
  42. Software Dev.  Other brand and product names mentioned in this handbook
  43. for identification purposes are trademarks or registered trademarks of
  44. their respective holders.
  45.  
  46.  
  47. ****************************************************************************
  48. *                                                                          *
  49. *******                           Contents                           *******
  50. *                                                                          *
  51. ****************************************************************************
  52.  
  53. 1. Introduction
  54.    1.1 What is CMATH ?
  55.    1.2 Licence Terms
  56.    1.3 Registered Version
  57.  
  58. 2. Getting Started
  59.    2.1 Installation
  60.    2.2 De-Installation
  61.  
  62. 3. Overview over the Functions of CMATH
  63.    3.1 Initialization of Complex Numbers
  64.    3.2 Data-Type Interconversions
  65.    3.3 Basic Complex Operations
  66.    3.4 Arithmetic Operations
  67.    3.5 Mathematical Functions
  68.  
  69. 4. Error Handling
  70.    4.1 General Error Handling of Complex Functions
  71.    4.2 Advanced Error Handling: Writing Messages into a File
  72.  
  73. 5. Syntax Reference
  74.    5.1 C++ Version
  75.    5.2 Plain-C Version
  76.  
  77. ****************************************************************************
  78. *                                                                          *
  79. *******                       1. Introduction                        *******
  80. *                                                                          *
  81. *****************************************************************************
  82.  
  83.  
  84. 1.1 What is CMATH ?
  85. -------------------
  86.  
  87. CMATH is a comprehensive library for complex-number arithmetis and
  88. mathematics. It is primarily intended as a high-quality replacement for
  89. the complex class libraries of popular C++ compilers. In addition,
  90. all functions may be called from C, without the necessity to use C++.
  91. Superior speed, accuracy and safety are achieved through the 
  92. implementation in Assembly language (as opposed to the compiled or 
  93. inline C++ code of the compilers' complex class libraries).
  94. Only for the most simple tasks, alternative inline C++ functions are used.
  95.  
  96. The implementation was guided by the following rules:
  97.  
  98.    1. Without any compromise, top priority is always given to the mathema-
  99.       tically correct result, with the accuracy demanded for the respective
  100.       data type. Especially for complex functions, this necessitates a
  101.       very thorough treatment of many different situations. To this end,
  102.       the various cases have to be distinguished with pedantic care.
  103.    2. Mathematical functions must be "safe" under all circumstances.
  104.       They may for no reason simply crash, but have to perform a decent
  105.       error treatment. This is true even - and perhaps especially - for
  106.       seemingly nonsense arguments, with the single exception of the
  107.       non-numbers INF and NAN, which occur themselves only as a result
  108.       of serious errors in other functions.
  109.    3. By all possible means, greatest execution speed must be attained.
  110.       (After all, you did not buy your fast computer for nothing!)
  111.    4. The program code has to be as compact as possible. However, in case
  112.       of conflicts, faster execution speed is always given priority
  113.       over smaller code size.
  114.  
  115. Having a look into the complex class libraries of popular compilers, you
  116. will immediately discover the differences between our approach and theirs.
  117. Often the mathematical functions are implemented by simply writing down the
  118. textbook formula. This yields relatively compact source code. But, due to
  119. round-off error of intermediate results, the final results returned by these
  120. functions are sometimes very inaccurate or even completely wrong. Moreover,
  121. they may lead to unhandled floating-point errors (this means: program crash!).
  122. Unnecessary to mention that the code thus generated is rather slow.
  123.  
  124. For programmers who prefer classis C-style functions over C++, CMATH
  125. provides all complex-number operations and functions also for the language C.
  126. This is accomplished through an additional set of alternative declarations
  127. of the complex types as structs in place of classes.
  128. Versions for Pascal and Fortran will be released soon, in which all
  129. functions shall have the same names as in the C version, as far as possible.
  130. The C++ classes and the C structs are binary compatible with each other.
  131. This point may become important for large projects with mixed C and C++
  132. modules.
  133.  
  134. Existing C++ code which uses the complex class library contained in
  135. <complex.h> can be left unchanged, because the CMATH functions and data
  136. types are also binary compatible with those of <complex.h>.
  137. Here is a detailed description of how to switch from the complex classes of
  138. Borland C++ to the new implementation given by CMATH:
  139.  
  140. *  In C++ modules, replace the statement
  141.        #include <complex.h>
  142.    by the statement
  143.        #include <newcplx.h>
  144.    Then, the following three complex classes are defined:
  145.    class complex<float>,  class complex<double>,
  146.    and  class complex<extended>.
  147.  
  148.    The data types fComplex, dComplex, and eComplex are defined as
  149.    synonyms for these classes.
  150.    In order to avoid the letter "L" (which is already over-used by "long int"
  151.    and "unsigned long" in the language C), the type "extended" is used here
  152.    as a synonym for "long double". Consequently, the complex data type
  153.    consisting of long doubles is named "eComplex". Thereby, the way is held
  154.    open for a future inclusion of whole-number complex types into CMATH.
  155.    Then,"liComplex" and "ulComplex" will denote the complex types consisting
  156.    of "long int" or "unsigned long" parts, respectively.
  157.  
  158. *  If you prefer to have the "classic" class complex of older releases
  159.    of Borland C++, you have to declare
  160.        #define CMATH_CLASSIC_COMPLEX
  161.    before (!) including <newcplx.h>.
  162.    In this case, only the class complex will be defined and gets the synonym
  163.    dComplex. Here you will have no access to the complex-number functions of
  164.    float and of extended precision.
  165.  
  166. *  For C modules, you cannot include <nexcplx.h>. Rather, please declare
  167.       #include <cmath.h>
  168.    If you are using only one level of floating-point precision, you may
  169.    wish to include only one of the type-specific include-files:
  170.    <cfmath.h>,  <cdmath.h>, or <cemath.h>, respectively.
  171.    The plain-C implementation of CMATH is based upon the following
  172.    definitions of the three complex data types:
  173.       typedef  struct { float     Re, Im; }  fComplex;
  174.       typedef  struct { double    Re, Im; }  dComplex;
  175.       typedef  struct { extended  Re, Im; }  eComplex;
  176.  
  177.    As described above, the data type "extended" is used as a synonym for
  178.    "long double", in order to avoid the letter "L".
  179.  
  180. *  In the C++ classes, the real and imaginary parts are declared as public
  181.    (in contrast to Borland C++ !) and named "Re" and "Im", respectively.
  182.    This allows to access them as "z.Re" and "z.Im"  in C++ modules as well
  183.    as in C modules.
  184.  
  185. The implementation described in this documentation refers to Borland C++,
  186. version 3.0 or later for DOS and Microsoft Windows 3.0 or later (or Win-OS
  187. sessions under IBM OS/2 2.0 or later; in the following, we will simply speak
  188. of "Windows"). The library for the memory model FLAT for Windows95 and
  189. WindowsNT requires Borland C++, version 4.0 or higher.
  190.  
  191. Depending on your choice when ordering or downloading the Shareware version
  192. of CMATH, you have got either of the following three library versions:
  193. memory model LARGE for DOS, LARGE for Windows 3.x, or FLAT for Windows95/NT.
  194. All of them require, at least, a 386 computer equipped with a 387
  195. coprocessor. This means: no emulation, no 486SX, but preferrably 486DX,
  196. Pentium or higher.
  197. The full (registered) version contains libraries for all memory models of
  198. DOS, 16-bit Windows and 32-bit Windows. These libraries in turn are shipped
  199. in three versions:
  200. one for 486DX and Pentium computers, the second for 386 with 387,
  201. the third for 286 with or without coprocessor, i.e. with emulation.
  202.  
  203.  
  204. 1.2 Licence Terms
  205. -----------------
  206.  
  207. This is the English Shareware version of CMATH for Borland C++ ("Software").
  208. It may be used under the following licence terms:
  209.  
  210. 1. You may test the SOFTWARE free of charge for an unlimited period of time.
  211.    This testing phase ends when you permanently integrate functions of this
  212.    SOFTWARE into any of your applications (programs, program parts...).
  213. 2. If you want to use this SOFTWARE for commercial purposes, you have
  214.    to purchase the registered version (see chapter 1.3).
  215. 3. Use of this SOFTWARE for educational purposes at schools and universities
  216.    remains free of charge. However, if any application created under these
  217.    terms is sold to others or otherwise used for commercial purposes,
  218.    paragraph 2 applies.
  219. 4. Distributing this SOFTWARE to others is allowed only in one of the
  220.    following two ways:
  221.    a) linked into your programs, so that the parts stemming from this
  222.       SOFTWARE do no longer appear as a library.
  223.    b) as a whole in unchanged form (in particular the Copyright and Licence
  224.       statements!), whereby you may ask a fee only and exclusively for the
  225.       physical act of copying the SOFTWARE.
  226. 5. This SOFTWARE is provided on an "as is" basis. Any explicit or implicit
  227.    warranties for the SOFTWARE are excluded.
  228.    Despite thorough testing of the SOFTWARE, errors and bugs cannot
  229.    be excluded with certainty. No claims as to merchantability or fitness
  230.    for a particular purpose are made.
  231.    You may not use the SOFTWARE in any environment or situation where
  232.    personal injury or excessive damage to anyone's property (including
  233.    your own) could arise from malfunctioning of the SOFTWARE.
  234.  
  235.  
  236. Copyright for the SOFTWARE and its documentation (C) 1996-1998 Martin Sander
  237.  
  238. All rights reserved, including those of translation into foreign languages.
  239.  
  240. Address of the author:
  241.               Dr. Martin Sander Software Development
  242.               Sertürnerstr. 11
  243.               D-37085 Göttingen
  244.               Germany
  245.               e-mail: MartinSander@Bigfoot.com
  246.  
  247.  
  248.  
  249. 1.3 Registered Version
  250. ----------------------
  251.  
  252. The full (registered) version of CMATH
  253.  
  254. -  supports all memory models of Windows95, NT, 3.x, and DOS
  255.  
  256. -  has individually optimized libraries for each degree of processor
  257.    backward-compatibility:
  258.       486DX/Pentium+
  259.       386+ (387 coprocessor required)
  260.       286+ (no coprocessor required).
  261.  
  262. -  comes with printed documentation.
  263.  
  264. -  can be ordered at the following conditions:
  265.  
  266.    a) if you can pay in German Marks (from 1999 on: in Euro)
  267.       and order directly from the author, the price is
  268.       DM  99,- for  1 unit,
  269.       DM 350,- for  5 units,
  270.       DM 600,- for 10 units    (incl. 16% VAT, plus DM 10,- handling charge).
  271.       Please order by sending an e-mail to MartinSander@bigfoot.com
  272.       or use a print-out of the file ORDER.TXT.
  273.       Payment options:
  274.           - pre-paid by DM Eurocheque
  275.           - C.O.D. (Cash-On-Delivery)
  276.           - upon invoice (only within Germany, net 14 days)
  277.  
  278.       If you have a European VAT ID, or if you order from outside the
  279.       European Union, you are exempt from the German VAT, but you may
  280.       have to pay your local VAT and/or import duties according to
  281.       local laws.
  282.  
  283.    b) International credit card or US-$ cheque payment is possible by
  284.       ordering through the following web-sites:
  285.  
  286.       http://www.atlantic-coast.com/cgi-bin/sellonline/136.htm
  287.       $ 60 for  1 unit,
  288.       $200 for  5 units,
  289.       $350 for 10 units
  290.       Add $5 for shipping&handling and applicable VAT.
  291.  
  292.  
  293.       http://www.shareit.com/programs/101353.htm
  294.       Price: $65 (including S&H). Add applicable VAT.
  295.       Alternatively, send an e-mail to register@shareit.com
  296.       US customers may also order by calling 1-800-903-4152
  297.       (orders only please!). US check and cash orders can be sent to 
  298.       ShareIt!'s US office at
  299.            ShareIt! Inc.
  300.            P.O. Box 97841 
  301.            Pittsburgh, PA 15227-0241
  302.            USA
  303.       * Please note the program No.: 101353 when ordering through ShareIt! *
  304.  
  305.  
  306.       USD prices are subject to change without notice, especially in the case
  307.       of strong exchange-rate fluctuations. Please see the actual prices
  308.       at the web-sites mentioned.
  309.  
  310. Purchasing the full (registered) version gives you the right to use it on
  311. as many computers at a time as the number of units you bought.
  312. Corporate site and world-wide licences are available upon request.
  313.  
  314.  
  315.  
  316. ****************************************************************************
  317. *                                                                          *
  318. *******                 2. Getting Started                           *******
  319. *                                                                          *
  320. ****************************************************************************
  321.  
  322. 2.1 Installation
  323. ----------------
  324. If you got CMATH as a part of OptiVec (a comprehensive library of
  325. vectorized functions by the same author), CMATH is automatically installed
  326. when you install OptiVec itself. In this case, installation of CMATH is
  327. already included and you should skip this chapter to continue with chapter 3.
  328.  
  329. Otherwise, please note the following points:
  330.  
  331. 1.  In order to use CMATH, you need an already installed copy of Borland
  332.     C/C++. Install CMATH by executing INSTALL.EXE on the installation disk.
  333.  
  334. 2.  Add the installation directory (which you chose during installation) to
  335.     the library search path and to the include-file search path of the IDE
  336.     and of the configuration file TURBOC.CFG, in case you are using the
  337.     command-line compiler.
  338.  
  339. 3.  Choose the desired platform (DOS, Windows3.x, or Win32).
  340.     If you chose DOS or Windows3.x, select the memory model LARGE.
  341.     (For Win32, it is automatically FLAT).
  342.     You should also choose 386 code generation and real coprocessor
  343.     commands (i.e., no emulation).
  344.  
  345. 4.  Add the desired CMATH library to your project list. For DOS programs,
  346.     this is the library CMATHL3.LIB, for Windows3.x you need CMATHL3W.LIB,
  347.     for Win32, CMATHF3W.LIB.
  348.  
  349. 5.  In your C++ programs, declare 
  350.          #include <newcplx.h>
  351.     For C modules, declare:
  352.          #include <cmath.h>
  353.     If you are using ObjectWindows, <newcplx.h> or <cmath.h>
  354.     must be included after(!) the include files for OWL.
  355.  
  356. 6. 16-bit programs only:
  357.     *   If the linker option "process extended dictionaries" is available
  358.         in your version of Borland C++, you must switch it on.
  359.         Otherwise, you might get a "Table limit exceeded" linker error.
  360.  
  361.     *   CMATH works with Borland (Turbo) C++, version 3.0 or higher. Since,
  362.         from version 4.0 on, Borland changed the name of the error handling
  363.         routine matherr (without underbar) into _matherr (with a leading
  364.         underbar), any 16-bit program using CMATH has to call a macro,
  365.         NEWMATHERR, which takes  care of redirecting calls to _matherr,
  366.         if necessary. You should place the call to NEWMATHERR into the
  367.         module containing  main() or OwlMain():
  368.  
  369.              #include .....
  370.              #include <nexcplx.h>   /* or: #include <cmath.h> */
  371.              NEWMATHERR
  372.  
  373.              int main( void )
  374.              {    ..........   }
  375.  
  376.         If you forget to call NEWMATHERR, you will get a linker error
  377.         "Unresolved external _matherr" in the Borland C versions from 4.0 on.
  378.  
  379.         Inclusion of the macro NEWMATHERR is not needed for 32-bit programs.
  380.  
  381. After these preparations, all CMATH functions are available for your programs.
  382.  
  383.  
  384. 2.2 De-Installation
  385. -------------------
  386.  
  387. Should you wish to remove CMATH from your computer after testing, please
  388. simply delete the directory CMATH with its subdirectories. The installation
  389. of CMATH does not affect any files outside its own directory, so there
  390. is nothing else to get rid of.
  391.  
  392.  
  393.  
  394. ****************************************************************************
  395. *                                                                          *
  396. *******       3. Overview over the Functions of CMATH                *******
  397. *                                                                          *
  398. ****************************************************************************
  399.  
  400. For C++, all functions of CMATH are declared in <nexcplx.h>.
  401. For C, there are the following three include-files:
  402. <cfmath.h> declares all functions for single precision (data type fComplex),
  403. <cdmath.h> contains all double-precision functions (data type dComplex), and
  404. <cemath.h> lists all functions for extended precision (data type eComplex).
  405. The include-file <cmath.h> unites the three include-files just mentioned.
  406.  
  407. In the following, it is often only the fComplex-version of a function that
  408. is explicitly mentioned. The versions for dComplex and eComplex are always
  409. exactly analogous.
  410.  
  411. All functions for the language C have a prefix denoting the data type on
  412. which the function works:
  413. "cf_" stands for single precision (arguments and return values of the data
  414.       type fComplex, sometimes together with float),
  415. "cd_" stands for double precision (dComplex and double), whereas
  416. "ce_" denotes extended-precision functions.
  417.  
  418. In C++, synonyms are defined for all these functions. The synonyms do not
  419. have a prefix, since the data type information is implicitly handled by the
  420. C++ compiler. The C++ function names are always identical to those found
  421. in the complex class libraries (if the respective function exists there).
  422. Of course, if you wish to use the C function names in your C++ modules,
  423. you can do so by including <cmath.h> instead of <newcplx.h>.
  424.  
  425.  
  426. 3.1 Initialization of Complex Numbers
  427. -------------------------------------
  428.  
  429. For C++ modules, there are several overloaded constructors:
  430.           fComplex fComplex( float RePart, float ImPart );
  431.           fComplex fComplex( float RePart );  // imaginary part always 0
  432.           fComplex fComplex( dComplex );
  433.           fComplex fComplex( eComplex );
  434.  
  435.           The interconversion between the complex types of different
  436.           level of accuracy may, in the course of down-conversions,
  437.           lead to OVERFLOW errors. These are are caught and treated
  438.           via _matherr.
  439.           Similarly to the constructor fComplex(), also dComplex() and
  440.           eComplex() exist in overloaded versions performing the same
  441.           tasks for the classes dComplex and eComplex, respectively.
  442.  
  443. Additionally, both in C++ and in plain-C modules, complex numbers may
  444. be initialized by separately assigning a value to the imaginary and
  445. real parts, e.g.:
  446.         z.Re = 3.0;   z.Im = 5.7;
  447.  
  448. Alternatively, in plain-C modules, the same initialization can be
  449. accomplished by the function fcplx:
  450.     z = fcplx( 3.0, 5.7 );
  451.  
  452. For double-precision complex numbers, use dcplx, for extended-precision
  453. complex numbers, use ecplx.
  454.  
  455. Since overloading of functions and constructors is specific to C++ and
  456. not available in plain C, the interconversions between the various
  457. complex types are performed via the functions
  458. cftocd,  cdtocf,  cftoce,  cetocf,  cdtoce,  and cetocd.
  459. As described above, OVERFLOW errors in the course of down-conversions
  460. are caught and treated via _matherr.
  461.  
  462. 3.2 Basic Complex Operations
  463. ----------------------------
  464.  
  465. The following basic complex operations are defined in CMATH:
  466.  
  467. C function  C++ synonym
  468. cf_conj     conj          complex-conjugate form,
  469. cf_neg      neg  (or -)   negation,
  470. cf_real     real          extraction of the real part,
  471. cf_imag     imag          extraction of the imaginary part,
  472. cf_polar    polar         conversion of polar coordinates into the "normal",
  473.                           Cartesian complex format
  474. cf_abs      abs           absolute value (magnitude of the pointer in the
  475.                           complex plane; this is treated as a math function
  476.                           with error handling),
  477. cf_arg      arg           argument (angle of the pointer in the complex
  478.                           plane),
  479. cf_norm     norm          norm (defined here as the square of the absolute
  480.                           value)
  481.  
  482. (The cd_ and ce_ versions are exactly analogous to the cf_ version)
  483.  
  484.  
  485. 3.3 Arithmetic Operations
  486. -------------------------
  487.  
  488. Only C++: The following set of operators is available for all of
  489.           the three complex classes:
  490.           +  -  *  /  +=  -=  *=  /=   ==   !=
  491.           These operators exist also for "mixed" arguments,
  492.           where one argument is complex, the other real and
  493.           where the arguments are of different floating-point
  494.           accuracies.
  495.  
  496. Since it is only the language C++, but not C, which allows to overload
  497. the arithmetic operators, all arithmetic operations of complex
  498. numbers are implemented in a different way for C modules. Here, we
  499. have the functions
  500.  
  501. cf_add        addition of two complex numbers
  502. cf_addRe      addition of a complex number and a real number
  503. cf_sub        subtraction of two complex numbers (first operand
  504.               minus the second operand)
  505. cf_subRe      subtraction of a real number from a complex number
  506. cf_subrRe     subtraction of a complex number from a real number
  507. cf_mul        multiplication of two complex numbers
  508. cf_mulRe      multiplication of a complex number and a real number
  509. cf_div        division of two complex numbers (first operand
  510.               divided by the second operand)
  511. cf_divRe      division of a complex number by a real number
  512. cf_divrRe     division of a real number by a complex number
  513.  
  514. (similarly the cd_ and ce_ versions)
  515.  
  516. The equality operator "=" is the only operator defined also in C for
  517. complex numbers.
  518.  
  519.  
  520. 3.4 Mathematical Functions
  521. --------------------------
  522.  
  523. CMATH contains all mathematical functions you would find in the complex
  524. class libraries, along with several additional ones:
  525.  
  526. C function   C++ synonym
  527. cf_abs       abs            ry = | zx |          absolute value
  528. cf_acos      acos           zy = acos( zx )      arcus cosine function
  529. cf_asin      asin           zy = asin( zx )      arcus sine function
  530. cf_atan      atan           zy = atan( zx )      arcus tangent function
  531. cf_cos       cos            zy = cos( zx )       cosine
  532. cf_cosh      cosh           zy = cosh( zx )      hyperbolic cosine
  533. cf_cubic     cubic          zy = zx**3           third power
  534. cf_exp       exp            zy = exp( zx )       exponential function
  535. cf_inv       inv            zy = 1.0 / zx        inverse
  536. cf_ipow      ipow           zy = zx**n           integer power
  537. cf_ln        ln             zy = ln( zx )        natural logarithm
  538. cf_log       log            zy = ln( zx )        identical to cf_ln, ln
  539. cf_log2      log2           zy = lb( zx )        binary logarithm
  540. cf_log10     log10          zy = lg( zx )        decadic logarithm
  541. cf_pow       pow            zy = zx**zexp        arbitrary power
  542. cf_powReBase pow, powReBase zy = r**zx           real base to complex power
  543. cf_powReExpo pow, powReExpo zy = zx**r           real power of complex base
  544. cf_quartic   quartic        zy = zx**4           fourth power
  545. cf_sin       sin            zy = sin( zx )       sine
  546. cf_sinh      sinh           zy = sinh( zx )      hyperbolic sine
  547. cf_square    square         zy = zx²             square
  548. cf_sqrt      sqrt           zy = sqrt( zx )      square root
  549. cf_tan       tan            zy = tan( zx )       tangent
  550. cf_tanh      tanh           zy = tanh( zx )      hyperbolic tangent
  551.  
  552. (similarly the cd_ and ce_ versions)
  553.  
  554.  
  555. ****************************************************************************
  556. *                                                                          *
  557. *******                      4. Error Handling                       *******
  558. *                                                                          *
  559. *****************************************************************************
  560.  
  561. 4.1 General Error Handling of Complex Functions
  562. -----------------------------------------------
  563.  
  564. The error handling of complex functions follows the rules employed also
  565. for real-number functions and operations. For all arithmetic operations,
  566. the design of the algorithms eliminates the danger of failure due to
  567. irregular intermediate results. Overflowing or otherwise irregular
  568. final results, however, will lead to a hardware interrupt being generated
  569. and, as a consequence, to a program abort.
  570.  
  571. In contrast to the arithmetic operations, all mathematical functions and
  572. all data-type interconversions perform a tight error checking and treat
  573. any detected error conditions via _matherr (for fComplex and dComplex
  574. functions) and _matherrl (for eComplex functions). All error messages
  575. eventually generated use the C name (and not the C++ synonym) of the
  576. failing function.
  577.  
  578. 16-bit programs only:
  579.    As mentioned already in chapter 2, Borland has changed the name of the
  580.    error-handling function "matherr" (without leading underbar), used in
  581.    the versions 3.x, into "_matherr" (with a leading underbar), from
  582.    version 4.0 on.
  583.    In order to make CMATH compatible with both the older and the later
  584.    versions of Borland C++, the following way of error handling was adopted:
  585.    In case of an error, all CMATH functions call primarily matherr (as in the
  586.    older versions of Borland C++). A macro NEWMATHERR provides for the
  587.    necessary redirection of these calls to _matherr, if a later version of
  588.    Borland C++ is used. Therefore, NEWMATHERR must be called once (!) in any
  589.    program using CMATH, after the inclusion of <cmath.h>. The best place
  590.    is the module containing the main(), WinMain(), or OWLMain() function:
  591.  
  592.        #include <cmath.h>
  593.        #include ...
  594.        NEWMATHERR
  595.          ......
  596.        main()
  597.        { ... }
  598.  
  599.  
  600. If you use CMATH as a part of OptiVec, consult also chapter 5 of
  601. HANDBOOK.TXT for further information on floating-point error handling.
  602. If you use CMATH separately from OptiVec, you should at least know
  603. about some advanced error handling features, borrowed from VectorLib and
  604. described in the following chapter.
  605.  
  606.  
  607. 4.2 Advanced Error Handling: Writing Messages into a File
  608. ---------------------------------------------------------
  609.  
  610. ANSI C provides the user-definable function perror to print error messages.
  611. However, several compilers, including Borland C++, do not use perror for
  612. this purpose. This means that the way error messages are printed is not
  613. controllable by the programmer. While this is fine in most instances, there
  614. may be situations in which you might, for example, wish the error messages
  615. not to be printed to the screen, but rather into a file, so that you could
  616. check later what has gone wrong. If you use Borland C++ for Windows, an
  617. additional motivation could come from the fact that, for any error, a
  618. message box is displayed and program execution interrupted until you
  619. acknowledge having taken notice of the error.
  620.  
  621. You might wish to circumvent this. To this end, CMATH borrows from OptiVec
  622. the function  V_setErrorEventFile. This function needs as arguments the
  623. desired name of your event file and a switch named ScreenAndFile which
  624. decides if the error message is printed only into the file, or additionally
  625. to the screen as well.
  626. Example:     V_setErrorEventFile( "MyErrors.LOG", 1 );
  627.  
  628. Note that this redirection of error messages is valid only for errors
  629. occurring in CMATH (and, of course, VectorLib) routines. If you care to
  630. do so, however, there is a way to extend the redirection also to
  631. "non-CMATH/VectorLib" functions:  you may modify  _matherr and _matherrl
  632. so that the statement
  633.     return 0;
  634. (which signals an unresolved error)  is replaced by the sequence
  635.     V_noteError( e->name, e->type ); return 1;
  636.  
  637. Thereby the task of printing the error message for unresolved errors is
  638. passed to V_noteError. Keep in mind that it is the return value of _matherr
  639. which decides if an error message is printed by the default error handler
  640. of Borland C/C++. Thus, after the call to V_noteError, the printing of the
  641. default error messages is by-passed by returning "1". (Also, do not forget
  642. that it is your(!) _matherr routine which determines which errors you accept
  643. and which not.)
  644.  
  645. For example, your _matherr function (matherr - without the leading underbar
  646. - for Borland C++ 3.0 and 3.1) might look like the following one:
  647.  
  648.     #include <math.h>
  649.     int  _matherr( struct exception *e)
  650.     {
  651.         if( (e->type == UNDERFLOW) ││ (e->type == TLOSS) )  /* ignore */ ;
  652.         else   /* all other errors deserve at least notice */
  653.         {
  654.               V_noteError( e->name, e->type );
  655.               if (e->type == DOMAIN) exit(1); /* really fatal */
  656.         }
  657.         return 1;
  658.     }
  659.  
  660. (Of course, if you decide to change _matherr, do not forget to change
  661. _matherrl in the same way!).
  662.  
  663. The default printing of error messages on the screen alone is restored by
  664. V_closeErrorEventFile().
  665.  
  666.  
  667. ****************************************************************************
  668. *                                                                          *
  669. *******               5. Syntax Reference                            *******
  670. *                                                                          *
  671. ****************************************************************************
  672.  
  673. In the following, the syntax of all CMATH functions of float / fComplex
  674. accuracy is given. The syntax of the functions for double and extended
  675. precisions is exactly analogous.
  676. If you chose the "classic" class complex, this is also similar.
  677. Just replace "float" by "double" and "fComplex" by "complex".
  678. (Of course, the type-casting operators and the interconversion functions
  679. do not exist if there is only one type.)
  680.  
  681. 5.1 C++ Version
  682. ---------------
  683. At this place, the syntax is given in a simplified form (just what you need
  684. to know in order to use these functions). For details of the declaration,
  685. see the class complex<float> in <nexcplx.h>.
  686. The arithmetic operators are not listed; their use is identical to the use
  687. of the real-number operators; suffice it to say they are all available.
  688.  
  689.     float     abs( fComplex _z );
  690.     fComplex  acos( fComplex _z );
  691.     float     arg( fComplex _z );
  692.     fComplex  asin( fComplex _z );
  693.     fComplex  atan( fComplex _z );
  694.     fComplex  cdtocf( dComplex cd );
  695.     fComplex  cetocf( eComplex ce );
  696.     fComplex  conj( fComplex _z );
  697.     fComplex  cos( fComplex _z );
  698.     fComplex  cosh( fComplex _z );
  699.     fComplex  cubic( fComplex _z ); 
  700.     fComplex  exp( fComplex _z );
  701.     fComplex  fComplex( float Re_part, float Im_part );
  702.     fComplex  fComplex( float Re_part );  // constructors
  703.     fComplex  fComplex( dComplex cd );
  704.     fComplex  fComplex( eComplex ce );   // type-casting constructors
  705.     float     imag();   // to be used as   zim = z.imag();
  706.     float     imag( fComplex _z );
  707.     fComplex  inv( fComplex _z );   
  708.     fComplex  ipow( fComplex __base, int __expon ); 
  709.     fComplex  ln( fComplex _z );
  710.     fComplex  log( fComplex _z ); 
  711.     fComplex  log2( fComplex _z );
  712.     fComplex  log10( fComplex _z );
  713.     fComplex  neg( fComplex _z );
  714.     float     norm( fComplex _z );
  715.     fComplex  polar( float _mag, float _angle=0 );
  716.     fComplex  pow( fComplex __base, float __expon );
  717.     fComplex  powReExpo( fComplex __base, float __expon );
  718.     fComplex  pow( float __base, fComplex __expon);
  719.     fComplex  powReBase( float __base, fComplex __expon );
  720.     fComplex  pow( fComplex __base, fComplex __expon);
  721.     fComplex  quartic( fComplex _z ); 
  722.     float     z.real();     // to be used as    zre = z.real();
  723.     float     real( fComplex _z );
  724.     fComplex  sin( fComplex _z );
  725.     fComplex  sinh( fComplex _z );
  726.     fComplex  sqrt( fComplex _z );
  727.     fComplex  square( fComplex _z );
  728.     fComplex  tan( fComplex _z );
  729.     fComplex  tanh( fComplex _z );
  730.     
  731.  
  732. 5.2 Syntax Reference for the Plain-C Version.
  733. Again, the syntax is given in a simplified form here. For details of
  734. the declaration, see <cfmath.h>.
  735. The prefix cf_ denotes the accuracy level "float / fComplex".
  736. For the functions of double/dComplex and extended/eComplex precisions,
  737. the prefixes are cd_ and ce_, respectively.
  738. Since overloaded operators are specific to C++, only the operator "="
  739. exists for plain C.
  740.  
  741.     float     cf_abs(  fComplex __z );
  742.     fComplex  cf_acos( fComplex __z );
  743.     fComplex  cf_add(   fComplex __x, fComplex __y );
  744.     fComplex  cf_addRe( fComplex __x, float __yRe );
  745.     float     cf_arg(  fComplex __z );
  746.     fComplex  cf_asin( fComplex __z );
  747.     fComplex  cf_atan( fComplex __z );
  748.     fComplex     cdtocf( dComplex __zd );
  749.     fComplex     cetocf( eComplex __ze );
  750.     fComplex  cf_conj( fComplex __z );
  751.     fComplex  cf_cos(  fComplex __z );
  752.     fComplex  cf_cosh( fComplex __z );
  753.     fComplex  cf_cubic( fComplex __z );
  754.     fComplex  cf_div(   fComplex __x, fComplex __y );
  755.     fComplex  cf_divRe( fComplex __x, float __yRe );   /*  x / yRe  */
  756.     fComplex  cf_divrRe( fComplex __x, float __yRe );  /*  yRe / x  */
  757.     fComplex  cf_exp(  fComplex __z );
  758.     fComplex  fcplx( float __ReVal, float __ImVal);
  759.     float     cf_imag( fComplex z );
  760.     fComplex  cf_inv(  fComplex __z );    /*   1.0 / z   */
  761.     fComplex  cf_ipow( fComplex __z, int __exponent );
  762.     fComplex  cf_ln(    fComplex __z );
  763.     fComplex  cf_log(   fComplex __z ); 
  764.     fComplex  cf_log2(  fComplex __z );
  765.     fComplex  cf_log10( fComplex __z );
  766.     fComplex  cf_mul(   fComplex __x, fComplex __y );
  767.     fComplex  cf_mulRe( fComplex __x, float __yRe );
  768.     fComplex  cf_neg(  fComplex __z );
  769.     float     cf_norm( fComplex __z );
  770.     fComplex  cf_polar( float __mag, float __angle );
  771.     fComplex  cf_pow( fComplex __base, fComplex __exponent );
  772.     fComplex  cf_powReBase( float __base, fComplex __exponent ); 
  773.     fComplex  cf_powReExpo( fComplex __base, float __exponent );
  774.     fComplex  cf_quartic( fComplex __z );  
  775.     float     cf_real( fComplex z );
  776.     fComplex  cf_sin(  fComplex __z );
  777.     fComplex  cf_sinh( fComplex __z );
  778.     fComplex  cf_square( fComplex __z );
  779.     fComplex  cf_sqrt( fComplex __z );
  780.     fComplex  cf_sub(   fComplex __x, fComplex __y );
  781.     fComplex  cf_subRe( fComplex __x, float __yRe );  /* x - yRe */
  782.     fComplex  cf_subrRe( fComplex __x, float __yRe ); /* yRe - x */
  783.     fComplex  cf_tan(  fComplex __z );
  784.     fComplex  cf_tanh( fComplex __z );
  785.  
  786.  
  787. *****************************************************************************
  788.  
  789. Although CMATH underwent thorough testing, there is always a possibility
  790. that a problem might have escaped our attention. Should you feel you dis-
  791. covered a "bug", please kindly try to specify the conditions under which
  792. you observed the problem as exactly as possible. Please let the author
  793. know what you have found!
  794. e-mail:  MartinSander@Bigfoot.com
  795.  
  796. Copyright (C) Martin Sander 1996-1998
  797.  
  798. *****************************************************************************
  799.